﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using sydfdl.TMS.Model;
using sydfdl.TMS.Tool;

namespace sydfdl.TMS.BLL
{
    public class BLLT_E_UploadOrder
    {
        /// <summary>
        /// 按货物查询
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="StartCity"></param>
        /// <param name="EndCity"></param>
        /// <returns></returns>
        public T_BaseTable GetOrderList(string xml, string StartCity, string EndCity)
        {
            T_BaseTable List = new T_BaseTable();
            #region
            SqlParameter[] para = {new SqlParameter("@para",SqlDbType.Xml,-1),
                                      new SqlParameter("@StartCity", SqlDbType.VarChar, 100) ,
                                      new SqlParameter("@EndCity", SqlDbType.VarChar, 100) };
            para[0].Value = xml;
            para[1].Value = StartCity;
            para[2].Value = EndCity;

            using (DataSet ds = SqlHelper.ExecuteProcedureToDataSet(@"P_E_GetArrivedOrderList", para, ""))
            {
                if (ds.Tables.Count>0)
                    List.total = ds.Tables[0].Rows.Count;
                if (ds.Tables[0].Rows.Count>0)
                {
                    DataTable dt = ds.Tables[0];
                    List.data = dt;
                }
            }
            #endregion
            return List;
        }

        /// <summary>
        /// 按车查询
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="StartCity"></param>
        /// <param name="EndCity"></param>
        /// <returns></returns>
        public T_BaseTable GetTurckList(string xml, string StartCity, string EndCity)
        {
            T_BaseTable List = new T_BaseTable();
            #region
            SqlParameter[] para = {new SqlParameter("@para",SqlDbType.Xml,-1),
                                      new SqlParameter("@StartCity", SqlDbType.VarChar, 100) ,
                                      new SqlParameter("@EndCity", SqlDbType.VarChar, 100) };
            para[0].Value = xml;
            para[1].Value = StartCity;
            para[2].Value = EndCity;

            using (DataSet ds = SqlHelper.ExecuteProcedureToDataSet(@"P_E_GetArrivedTruckList", para, ""))
            {
                if (ds.Tables.Count > 0)
                    List.total = ds.Tables[0].Rows.Count;
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    List.data = dt;
                }
            }
            #endregion
            return List;
        }

        /// <summary>
        /// 整车签收入库
        /// </summary>
        /// <param name="TruckID"></param>
        /// <returns></returns>
        public string SingIn(string TruckID)
        {
            string Result = "";
            SqlParameter[] para = { new SqlParameter("@TruckID", SqlDbType.VarChar, 100), new SqlParameter("@ReturnValue", SqlDbType.VarChar, 100) };
            para[0].Value = TruckID;
            para[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.tmsConn, CommandType.StoredProcedure, @"P_E_GetArrivedSignTruckIn", para);
            Result = para[1].Value.ToString();
            return Result;
        }

        public T_BaseTable GetGoodsDetailByTruck(string TruckID)
        {
            T_BaseTable List = new T_BaseTable();
            #region
            SqlParameter[] para = {new SqlParameter("@TruckID",SqlDbType.VarChar,100) };
            para[0].Value = TruckID;

            using (DataSet ds = SqlHelper.ExecuteProcedureToDataSet(@"P_E_GetArrivedGoodsDetailByTruck", para, ""))
            {
                if (ds.Tables.Count > 0)
                    List.total = ds.Tables[0].Rows.Count;
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    List.data = dt;
                }
            }
            #endregion
            return List;
        }
    }
}
